</para>
+<!-- ##### SECTION Stability_Level ##### -->
+
+
<!-- ##### STRUCT GdkAtom ##### -->
<para>
An opaque type representing a string as an index into a table
</para>
<note>
<para>
-The <function>XGetWindowProperty()</function>
-function that gdk_property_get()
-uses has a very confusing and complicated set of semantics.
+The XGetWindowProperty() function that gdk_property_get()
+uses has a very confusing and complicated set of semantics.
Unfortunately, gdk_property_get() makes the situation
worse instead of better (the semantics should be considered
undefined), and also prints warnings to stderr in cases where it
should return a useful error to the program. You are advised to use
-<function>XGetWindowProperty()</function>
-directly until a replacement function for gdk_property_get()
+XGetWindowProperty() directly until a replacement function for
+gdk_property_get()
is provided.
</para>
</note>
be filled in, a warning will be printed to stderr
and no data will be returned.
@offset: the offset into the property at which to begin
- retrieving data. (in 4 byte units!)
-@length: the length of the data to delete. (in bytes, but
- the actual retrieved length will be the next
- integer multiple multiple of four greater than
- this!)
+ retrieving data, in 4 byte units.
+@length: the length of the data to retrieve in bytes. Data is
+ considered to be retrieved in 4 byte chunks, so @length
+ will be rounded up to the next highest 4 byte boundary
+ (so be careful not to pass a value that might overflow
+ when rounded up).
@pdelete: if %TRUE, delete the property after retrieving the
data.
@actual_property_type: location to store the actual type of
the property.
-@actual_format: location to store the actual format of the data.
-@actual_length: location to store the length of the retrieved
- data, in bytes.
+@actual_format: location to store the actual return format of the
+ data; either 8, 16 or 32 bits.
+@actual_length: location to store the length of the retrieved data, in
+ bytes. Data returned in the 32 bit format is stored
+ in a long variable, so the actual number of 32 bit
+ elements should be be calculated via
+ @actual_length/sizeof(glong) to ensure portability to
+ 64 bit systems.
@data: location to store a pointer to the data. The retrieved
data should be freed with g_free() when you are finished
using it.
gint ret_format;
gulong ret_nitems;
gulong ret_bytes_after;
+ gulong get_length;
gulong ret_length;
guchar *ret_data;
Atom xproperty;
ret_data = NULL;
+ /*
+ * Round up length to next 4 byte value. Some code is in the (bad?)
+ * habit of passing G_MAXLONG as the length argument, causing an
+ * overflow to negative on the add. In this case, we clamp the
+ * value to G_MAXLONG.
+ */
+ get_length = length + 3;
+ if (get_length > G_MAXLONG)
+ {
+ g_warning ("gdk_property_get(): length value has wrapped in calculation "
+ "(did you pass G_MAXLONG?)");
+ get_length = G_MAXLONG;
+ }
+ /* To fail, either the user passed 0 or G_MAXULONG */
+ get_length = get_length / 4;
+ if (get_length == 0)
+ {
+ g_warning ("gdk_propery-get(): invalid length 0");
+ return FALSE;
+ }
+
res = XGetWindowProperty (GDK_DISPLAY_XDISPLAY (display),
GDK_WINDOW_XWINDOW (window), xproperty,
- offset, (length + 3) / 4, pdelete,
+ offset, get_length, pdelete,
xtype, &ret_prop_type, &ret_format,
&ret_nitems, &ret_bytes_after,
&ret_data);